package com.cskaoyan.controller.back;

import com.cskaoyan.bean.po.CommonData;
import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.bean.vo.back.BaseRespVo;
import com.cskaoyan.bean.vo.back.CreateGoodsCategoryVO;
import com.cskaoyan.bean.vo.back.ShowGoodsCategoryVO;
import com.cskaoyan.service.back.CategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品类目
 *
 * @auther 10-何兴绕
 * @Date 2022年10月11日 17:19
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    /**
     * 展示商品类
     *
     * @return CommonData
     */
    @RequiresPermissions("admin:category:list")
    @GetMapping("list")
    public BaseRespVo showGoodsCategory() {
        CommonData goodsCategory = categoryService.getGoodsCategory();
        return BaseRespVo.ok(goodsCategory);
    }

    /**
     * 获取商品类目标签
     *
     * @return
     */
    @GetMapping("l1")
    public BaseRespVo GetGoodsLabel() {
        CommonData goodsLabel = categoryService.getGoodsLabel();
        return BaseRespVo.ok(goodsLabel);
    }

    /**
     * 创建商品类目
     * @param marketCategory
     * @return
     */
    @RequiresPermissions("admin:category:create")
    @PostMapping("create")
    public BaseRespVo createGoodsCategory(@RequestBody MarketCategory marketCategory) {
        CreateGoodsCategoryVO goodsCategory = categoryService.createGoodsCategory(marketCategory);
        return BaseRespVo.ok(goodsCategory);
    }

    /**
     * 更新商品类目
     * @param showGoodsCategoryVO
     * @return
     */
    @RequiresPermissions("admin:category:update")
    @PostMapping("update")
    public BaseRespVo updateGoodsCategory(@RequestBody ShowGoodsCategoryVO showGoodsCategoryVO) {
        int code = categoryService.updateGoodsCategory(showGoodsCategoryVO);
        return BaseRespVo.ok();
    }

    /**
     * 删除商品类目
     * @param showGoodsCategoryVO
     * @return
     */
    @RequiresPermissions("admin:category:delete")
    @PostMapping("delete")
    public BaseRespVo deleteGoodsCategory(@RequestBody ShowGoodsCategoryVO showGoodsCategoryVO) {
        int code = categoryService.deleteGoodsCategory(showGoodsCategoryVO);
        return BaseRespVo.ok();
    }
}
